package cn.vc.content.controller.video;

import cn.vc.auth.entity.po.VUser;
import cn.vc.basicmodule.entity.Result;
import cn.vc.content.service.video.VideoCollectService;
import cn.vc.content.service.video.VideoService;
import cn.vc.content.util.SecurityUtil;
//import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/videocollect")
//@PreAuthorize("hasAnyAuthority('ordinary')")
public class VideoCollectController {
    @Autowired
    private VideoCollectService videoCollectService;
//    private final AmqpTemplate amqpTemplate;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private VideoService videoService;


    /**
     * <h2>收藏视频</h2>
     * @param id
     * @return
     */
    @PostMapping("/{id}")
    public Result<?> collectOrNot(@PathVariable("id") Long id) {
        VUser myUser = SecurityUtil.getUser();
        if (myUser==null) return Result.NOT_LOGGED_IN();

        boolean bo = videoCollectService.collect(id, myUser.getId());
        if (bo) {
            videoService.collect(id);
        } else {
            videoService.noCollect(id);
        }
        return new Result<>(bo);
    }

}
